package com.dd.service.impl;

import com.dd.entity.Inventory;
import com.dd.entity.InventoryVO;
import com.dd.mapper.InventoryMapper;
import com.dd.service.IInventoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 库存表 服务实现类
 * </p>
 *
 * @author dhd
 * @since 2024-10-21
 */
@Service
public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory> implements IInventoryService {
    @Autowired
    InventoryMapper inventoryMapper;

    @Override
    public Inventory selectAllByProductId(Integer productId) {
        return inventoryMapper.selectAllByProductId(productId);
    }

    @Override
    public int updateQuantityAndCreatedTime(int quantity, int productId) {
        return inventoryMapper.updateQuantityAndCreatedTime(quantity,productId);
    }

    @Override
    public int insertQuantityAndCreatedTime(int quantity, int productId) {
        return inventoryMapper.insertQuantityAndUpdatedTime(quantity,productId);
    }

    @Override
    public PageInfo<InventoryVO> selectAllInventory(int pageNum, String productName) {
        PageHelper.startPage(pageNum,5);
        List<InventoryVO> inventoryVOS = inventoryMapper.selectAllInventory(productName);
        PageInfo<InventoryVO> pageInfo = new PageInfo<>(inventoryVOS);
        return pageInfo;
    }
}
